<?php

namespace App\Domain\Role\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Domain\Role\Dao\RoleDao;

class RolePost extends FormRequest
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'roleId' => ["required", function ($attribute, $value, $fail) {
                if ($value != '-1') {
                    $role = (new RoleDao())::findById($value);
                    if (!$role) {
                        $fail("角色不存在");
                    }
                }
//                if ($value == '1') {
//                    $fail("超级管理员角色不可修改");
//                }
            }],
            'roleName' => 'required_with_out:roleId|nullable',
            'describe' => 'present|between:0,100|nullable',
            'jurisdiction' => 'present|nullable|exists:permissions,id',
        ];
    }

    public function messages()
    {
        return [

        ];
    }

    public function attributes()
    {
        return [
            'roleName' => '角色名称',
            'describe' => '角色说明',
            'jurisdiction' => '权限',

        ];
    }
}

